$(function () {
    obj.init();
});

var obj = new function () {
    return {
        init: function () {
            this.funObj().showData(true);
            this.listener();
        },
        listener: function () {
            var $this = this;
            $('#do_status').on('click',function () {
                $this.funObj().showData(false);
            });
        },
        funObj: function () {
            var $this = this;
            return {
                showData: function (_isFirst) {
                    var iId = $('#iId').val();
                    var startDate = $('#startTime').val();
                    var endDate = $('#endTime').val();
                    if (!startDate || !endDate) {
                        if (_isFirst) {
                            return false;
                        } else {
                            window.top.xhTop.showError('请选择开始/结束时间');
                            return false;
                        }
                    } else {
                        xhExtra.ajaxRequest('bpm/operate_pro/getStatTeaApp', {iId: iId, startDate: startDate, endDate: endDate}, {check:true}, function (data) {
                            var str = '<tr class="info teaTitle">' +
                                '<th style="width: 25%;text-align: center;">老师</th>' +
                                '<th style="width: 25%;text-align: center;">应用</th>' +
                                '<th style="width: 25%;text-align: center;">类型</th>' +
                                '<th style="width: 25%;text-align: center;">完成情况</th>' +
                                '</tr>';
                            if(data!=null && data.length>0 ) {
                                $.each(data, function (index, row) {
                                    str += '<tr style="background-color: #f9f9f9;">';
                                    if (row.isTeaFirstRow) {
                                        str += '<td rowspan="' + row.teaRowSpan + '">' + row.teaName + '</td>';
                                    }
                                    if (row.isAppFirstRow) {
                                        str += '<td rowspan="' + row.appRowSpan + '">' + row.appName + '</td>';
                                    }
                                    str += '<td>' + row['type'] + '</td>';
                                    str += '<td>' + row['finish'] + '</td>';
                                    str += '</tr>'
                                })
                            }
                            $('#showStatData').find('table').empty().append(str);
                        });
                    }
                }
            }
        }
    }
};